package com.astoolkit.workflow.task.events
{
	import com.astoolkit.workflow.BasePipelineTask;
	
	import flash.events.Event;
	import flash.events.IEventDispatcher;
	
	public class WaitForEvent extends BasePipelineTask
	{
		public var target : IEventDispatcher;
		public var eventType : String;
		
		override public function prepare():void
		{
			super.prepare();
			if( !target || !eventType ) 
			{
				fail( "No target and/or eventType provided" );
				return;
			}
			target.addEventListener( eventType, onEvent, false, int.MIN_VALUE );
		}
		
		override public function begin(inRetain:Boolean=false):void
		{
			super.begin(inRetain);
		}
		
		private function onEvent( inEvent : Event ) : void
		{
			target.removeEventListener( eventType, onEvent );
			complete();
		}
	}
	
}